﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Copy4Backup
{
	/// <summary>
	/// File filter.
	/// </summary>
	public class FileFilter
	{

		#region Fields

		/// <summary>
		/// Holds the extention filter.
		/// </summary>
		private readonly String filter_;
		#endregion Fields

		#region Properties
		#endregion Properties

		#region Methods

		/// <summary>
		/// Prevents a default instance of the FileFilter class from being created.
		/// </summary>
		private FileFilter()
		{
		}

		/// <summary>
		/// Initializes a new instance of the FileFilter class.
		/// </summary>
		/// <param name="filter"></param>
		public FileFilter(String filter)
		{
			int index = filter.LastIndexOf('.');
			if (0 > index)
			{
				filter_ = "." + filter;
			}
			else
			{
				filter_ = filter.Substring(index);
			}
		}

		/// <summary>
		/// Checks, if the file name has the extention specified in the ctor filter text.
		/// </summary>
		/// <param name="file">The file name to check.</param>
		/// <returns>True, if the file name has the extention specified in the ctor filter text.</returns>
		public bool Matched(String file)
		{
			return file.EndsWith(filter_, StringComparison.CurrentCultureIgnoreCase);
		}
		#endregion Methods
	}
}
